package com.chainyoung.component_tmmarket.mvp.model;

import com.chainyoung.common.appcommon.hdwallet.EtherscanService;
import com.chainyoung.common.di.scope.FragmentScope;
import com.chainyoung.common.integration.IRepositoryManager;
import com.chainyoung.common.mvp.BaseModel;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmmarket.api.MarketService;
import com.chainyoung.component_tmmarket.bean.Kline;
import com.chainyoung.component_tmmarket.bean.MarketList;
import com.chainyoung.component_tmmarket.mvp.contract.MarketListContract;
import com.chainyoung.component_tmmarket.mvp.contract.MarketMainContract;

import org.json.JSONObject;

import java.util.List;
import java.util.TreeMap;

import javax.inject.Inject;

import io.reactivex.Flowable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;
import okhttp3.ResponseBody;


public class MarketListModel extends BaseModel implements MarketListContract.Model {

    @Inject
    public MarketListModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }


    @Override
    public Flowable<String> getMarketList(TreeMap<String, Object> map) {
        return mRepositoryManager.obtainRetrofitService(MarketService.class)
                .getMarketListDetail(map)
                .map(new Function<ResponseBody, String>() {
                    @Override
                    public String apply(@NonNull ResponseBody body) throws Exception {
                        return new JSONObject(body.string()).getString("data");
                    }
                });
    }


}
